<script setup>
import {articleList1, articleList2} from "@/config/kb_articles";
import {computed, ref} from 'vue'
import {useRouter} from "vue-router";

const router = useRouter();
let articleObj = {
  title: 'Discuz/DiscuzX',
  brief: 'Discuz!X官方开源饭，简体中义 UTF8 编码。中国领先的社区软件服务商，' +
      '22 年间为 300 万企业及站长时能，拥有超过 7000 款应用，全球成熟应最高，泰盖率量' +
      '大的处站系统之一。第承“开放、连接全球成熟应最高，泰盖率量大的处站系统之一。第承“开放、连'+
      '大的处站系统之一。第承“开放、连接全球成熟应最高，泰盖率量大的处站系统之一。第承“开放、连+' +
      '大的处站系统之一。第承“开放、连接全球成熟应最高，泰盖率量大的处站系统之一。第承“开放、连',
  tags: ['Java面向对象程序设计', 'JavaEE企业应用开发']
}
let articleList = ref(Array(10).fill(articleObj));  // 文章列表
const TagList = [
  '全部',
  'Java面向对象程序设计',
  'JavaEE企业应用开发',
  'UML面向对象分析与设计',
  '移动应用开发',
  '数据库原理与应用',
  '高级语言程序设计',
  'Web前端开发技术',
  'Unix操作系统',
  '通信与计算机网络',
  '管理信息系统',
  '商务智能',
  '数据化决策',
  '计算智能',
  '现代软件开发技术',
  '软件体系结构',
  '软件质量保证与测试',
  '计算机强化训练',
  '大学生创新创业基础',
  '信息系统项目管理',
  '系统工程专题',
]
// TODO: 固定静态文章选择待修改
const showArticleList = computed(()=>{
  return activeTagIdx.value === 0 ? articleList1:articleList2;
})
let activeTagIdx = ref(0);

const PageSize = 10;
let text = ref('');
let total = ref(10);
let isAsc = ref(false);
const handleCurrentChange = ()=>{
  console.log('页面发生更改');
}

</script>
<template>
<div class="kbase">
  <div class="topSearch">
    <div class="search">
      <img src="@/assets/images/搜索.png">
      <input type="text" v-model="text">
      <div class="searchBtn">
        <button class="btn" @click="search">搜 索</button>
      </div>
    </div>
  </div>
  <div class="tag-container">
      <span class="tag" v-for="(tagName,idx) in TagList" :key="idx" @click="activeTagIdx = idx">
        <el-tag :effect="idx === activeTagIdx ? 'dark':'light'">{{'#'+tagName}}</el-tag>
      </span>
  </div>
  <div class="article-wrapper">
    <div class="wrapper-top">
      <div class="count"> {{ total }}条消息</div>
      <div class="sort">
        <span>热度排序</span>
        <img src="@/assets/images/arrow-up-icon.png" class="icon" @click="isAsc = true">
        <img src="@/assets/images/arrow-down-icon.png" class="icon" @click="isAsc = false">
      </div>
    </div>
    <div class="wrapper-body">
      <ul class="article-list">
        <li
            v-for="(item, index) in showArticleList"
            :key="index"
            class="article-card-item"
            @click="router.push({
              name: 'article',
              params: {
                id: 1
              }
            })"
        >
          <div class="title">{{item.title}}</div>
          <div class="brief">{{item.content}}</div>
          <div class="tags">
            <el-tag v-for="(tName,idx) in item.tags" :key="idx">{{tName}}</el-tag>
          </div>
        </li>
      </ul>
    </div>
    <div class="wrapper-bottom">
      <el-pagination
          @current-change="handleCurrentChange"
          layout="prev, pager, next"
          :total="total"
          :page-size="PageSize"
          :hide-on-single-page="false"
      >
      </el-pagination>
    </div>
  </div>
</div>
</template>

<style scoped lang="less">
.topSearch {
  position: relative;
  .search {
    box-sizing: border-box;
    border: 1px solid black;
    border-radius: 20px;
    width: 700px;
    height: 40px;
    margin: 0 auto;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;

    img {
      width: 20px;
      height: 20px;
    }

    input {
      border: 0;
      font-size: medium;
      outline: none;
      width: 80%;
      height: 30px;
    }

    .searchBtn .btn {
      width: 80px;
      height: 26px;
      background-color: #62c4da;
      border-radius: 14px;
      font-weight: 600;
      color: whitesmoke;
      border-style: none;
      word-spacing: 6px;
      text-align: center;
      cursor: pointer;
    }
  }
  .post-btn {
    width: 100px;
    height: 32px;
    border-radius: 16px;
    background-color: #62c4da;
    text-align: center;
    line-height: 32px;
    position: absolute;
    right: 50px;
    top: 4px;
    color: white;
    cursor: pointer;
  }
}

.tag-container {
  padding: 20px;
  span.tag {
    display: inline-block;
    margin-right: 5px;
    margin-bottom: 5px;
    cursor: pointer;
  }
}

.article-wrapper {
  padding: 0 0 20px;
}

.wrapper-top {
  height: 30px;
  line-height: 30px;
  padding: 0 10px;
  border-bottom: 1px solid black;
  font-size: 14px;

  .count {
    float: left;
  }

  .sort {
    float: right;
    display: flex;
    align-items: center;

    span {
      margin-right: 10px;
    }

    img.icon {
      width: 15px;
      margin-right: 3px;
      cursor: pointer;
    }
  }
}
.article-list {
  .article-card-item {
    padding: 10px;
    position: relative;
    cursor: pointer;
    &::after {
      content: '';
      text-indent: 9999px;
      width: 100%;
      height: 0;
      border-bottom: 1px solid gray;
      //background-color: gray;
      position: absolute;
      bottom: 0;
      left: 0;
    }
    .title {
      font-weight: 700;
      font-size: 16px;
      color: #1c668b;
      line-height: 24px;
    }
    .brief {
      height: 45px;
      font-size: 14px;
      color: #555;
      margin: 18px 0;
      line-height: 1.5;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      word-break: break-all;
      text-overflow: ellipsis;
      position: relative;
      box-sizing: border-box;
    }
    .tags {
      display: flex;
      gap: 5px;
    }
  }
}

</style>